﻿using MediatR;
using W.Carrier.Api.Application.Command;
using W.Carrier.Repostiory.Interface;

namespace W.Carrier.Api.Application.CommandHandler
{
    public class CarrierDeleteCommandHandler:IRequestHandler<CarrierDeleteCommand,int>
    {
        private readonly ICarrierInfoRepository _icarrierInfoRepository;
        public CarrierDeleteCommandHandler(ICarrierInfoRepository icarrierInfoRepository)
        {
            _icarrierInfoRepository = icarrierInfoRepository;
        }

        public async Task<int> Handle(CarrierDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = await _icarrierInfoRepository.GetModelAsync(request.CarrierId);
            if (list!=null)
            {
                list.IsDelete = true;
            }
            int n = await _icarrierInfoRepository.Update(list);
            return n;
        }
    }
}
